<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/blog/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/blog/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT" />










<meta name="description" content="####1. 单个项目设置代理在项目的根目录下的gradle.properties文件中添加123456systemProp.http.proxyHost=127.0.0.1# 代理软件端口systemProp.http.proxyPort=1080systemProp.https.proxyHost=127.0.0.1# 代理软件端口systemProp.https.proxyPort=1080">
<meta name="keywords" content="Android、iOS、Web、React Native">
<meta property="og:type" content="article">
<meta property="og:title" content="Android-Gradle详解">
<meta property="og:url" content="http://yoursite.com/blog/2018/08/06/Android-Special-Function/Android-Gradle详解/index.html">
<meta property="og:site_name" content="凌浩雨_博客">
<meta property="og:description" content="####1. 单个项目设置代理在项目的根目录下的gradle.properties文件中添加123456systemProp.http.proxyHost=127.0.0.1# 代理软件端口systemProp.http.proxyPort=1080systemProp.https.proxyHost=127.0.0.1# 代理软件端口systemProp.https.proxyPort=1080">
<meta property="og:locale" content="default">
<meta property="og:updated_time" content="2018-08-06T11:08:35.770Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Android-Gradle详解">
<meta name="twitter:description" content="####1. 单个项目设置代理在项目的根目录下的gradle.properties文件中添加123456systemProp.http.proxyHost=127.0.0.1# 代理软件端口systemProp.http.proxyPort=1080systemProp.https.proxyHost=127.0.0.1# 代理软件端口systemProp.https.proxyPort=1080">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/blog/2018/08/06/Android-Special-Function/Android-Gradle详解/"/>





  <title>Android-Gradle详解 | 凌浩雨_博客</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="default">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">凌浩雨_博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            Archives
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/blog/blog/2018/08/06/Android-Special-Function/Android-Gradle详解/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="凌浩雨">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.jpeg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="凌浩雨_博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Android-Gradle详解</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2018-08-06T18:01:38+08:00">
                2018-08-06
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>####1. 单个项目设置代理<br>在项目的根目录下的gradle.properties文件中添加<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">systemProp.http.proxyHost=127.0.0.1</span><br><span class="line"># 代理软件端口</span><br><span class="line">systemProp.http.proxyPort=1080</span><br><span class="line">systemProp.https.proxyHost=127.0.0.1</span><br><span class="line"># 代理软件端口</span><br><span class="line">systemProp.https.proxyPort=1080</span><br></pre></td></tr></table></figure></p>
<a id="more"></a>
<p>####2. 全局代理设置<br>在<code>C:\Users\Administrator\</code>(其中Administrator是用户名)下, 新建gradle.properties文件，往里面添加如下内容.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">systemProp.http.proxyHost=127.0.0.1</span><br><span class="line"># 代理软件端口</span><br><span class="line">systemProp.http.proxyPort=1080</span><br><span class="line">systemProp.https.proxyHost=127.0.0.1</span><br><span class="line"># 代理软件端口</span><br><span class="line">systemProp.https.proxyPort=1080</span><br></pre></td></tr></table></figure></p>
<p>####3. 签名文件配置<br>1). 在主module根目录下的新建signing.properties文件<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">KEYSTORE_FILE=你的keystore文件位置</span><br><span class="line">KEYSTORE_PASSWORD= 你的keystore文件密码</span><br><span class="line">KEY_ALIAS= 你的keystore文件用到的别名</span><br><span class="line">KEY_PASSWORD= 你的keystore文件用到的别名的密码</span><br></pre></td></tr></table></figure></p>
<p>2). build.gradle加载<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">//加载签名配置的文件</span><br><span class="line">Properties props = new Properties()props.load(new</span><br><span class="line">FileInputStream(file(&quot;signing.properties&quot;)))</span><br><span class="line">android &#123;</span><br><span class="line">  signingConfigs &#123;    </span><br><span class="line">    release&#123;        </span><br><span class="line">        //设置release的签名信息       </span><br><span class="line">        keyAlias props[&apos;KEY_ALIAS&apos;]        </span><br><span class="line">        keyPassword props[&apos;KEY_PASSWORD&apos;]        </span><br><span class="line">        storeFile file(props[&apos;KEYSTORE_FILE&apos;])        </span><br><span class="line">        storePassword props[&apos;KEYSTORE_PASSWORD&apos;]    </span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">...</span><br><span class="line"></span><br><span class="line">  buildTypes &#123;</span><br><span class="line">      debug &#123;</span><br><span class="line">        ...</span><br><span class="line">        signingConfig signingConfigs.release</span><br><span class="line">      &#125;</span><br><span class="line">      ...    </span><br><span class="line">      release &#123;</span><br><span class="line">        ...</span><br><span class="line">        signingConfig signingConfigs.release</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>####4.  多渠道打包<br>1). 配置AndroidManifest.xml<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;meta-data android:name=&quot;UMENG_CHANNEL&quot; android:value=&quot;$&#123;UMENG_CHANNEL_VALUE&#125;&quot; /&gt;</span><br></pre></td></tr></table></figure></p>
<p>2). build.gradle文件中的设置<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">productFlavors &#123; </span><br><span class="line">  wandoujia  &#123; </span><br><span class="line">    manifestPlaceholders = [UMENG_CHANNEL_VALUE: &quot;wandoujia&quot;] </span><br><span class="line">  &#125; </span><br><span class="line">  xiaomi  &#123; </span><br><span class="line">    manifestPlaceholders = [UMENG_CHANNEL_VALUE: &quot;xiaomi&quot;] </span><br><span class="line">  &#125;</span><br><span class="line">  qq  &#123; </span><br><span class="line">    manifestPlaceholders = [UMENG_CHANNEL_VALUE: &quot;qq&quot;] </span><br><span class="line">  &#125; </span><br><span class="line">  360  &#123; </span><br><span class="line">    manifestPlaceholders = [UMENG_CHANNEL_VALUE: &quot;360&quot;] </span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>简便写法：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">android &#123;</span><br><span class="line">  ...</span><br><span class="line"></span><br><span class="line">  buildTypes &#123;</span><br><span class="line">      debug &#123;</span><br><span class="line">        ...</span><br><span class="line">      &#125;</span><br><span class="line">      ...    </span><br><span class="line">      release &#123;</span><br><span class="line">        ...</span><br><span class="line">        productFlavors &#123; </span><br><span class="line">            wandoujia&#123;&#125; </span><br><span class="line">            xiaomi&#123;&#125; </span><br><span class="line">            qq&#123;&#125; </span><br><span class="line">            360 &#123;&#125; </span><br><span class="line">        &#125; </span><br><span class="line">        productFlavors.all &#123; flavor -&gt; flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name] </span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>3). 一次生成所有渠道包<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">gradle assembleRelease</span><br></pre></td></tr></table></figure></p>
<p>4). 修改导出包的文件目录和apk名称<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line">ext &#123;</span><br><span class="line">    out_put_file = &quot;G:\\test&quot;</span><br><span class="line">&#125;</span><br><span class="line">// 定义一个打包时间</span><br><span class="line">def releaseTime() &#123;    </span><br><span class="line">      return new Date().format(&quot;yyyyMMdd&quot;, TimeZone.getTimeZone(&quot;UTC&quot;))</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">android &#123;</span><br><span class="line">  ...</span><br><span class="line"></span><br><span class="line">  buildTypes &#123;</span><br><span class="line">      debug &#123;</span><br><span class="line">        ...</span><br><span class="line">      &#125;</span><br><span class="line">      ...    </span><br><span class="line">      release &#123;</span><br><span class="line">        ...</span><br><span class="line">        applicationVariants.all &#123;</span><br><span class="line">                variant -&gt; variant.outputs.each &#123; output -&gt;</span><br><span class="line">                    def outputFile = output.outputFile</span><br><span class="line"></span><br><span class="line">                    if (null != outputFile &amp;&amp; outputFile.name.endsWith(&apos;.apk&apos;)) &#123;</span><br><span class="line">                        // 输出apk名称为debug_v1.0.0_2018_03_21.apk</span><br><span class="line">                        def isDebug = outputFile.name.split(&apos;.apk&apos;)[0].toString().split(&apos;-&apos;)[1]</span><br><span class="line">                        def fileName = &quot;$&#123;isDebug&#125;_v$&#123;defaultConfig.versionName&#125;_$&#123;releaseTime()&#125;.apk&quot;</span><br><span class="line">                        // 控制输出APK的存放路径</span><br><span class="line">                        if (!&quot;&quot;.equals(out_put_file)) &#123;</span><br><span class="line">                            File output_dir = file(out_put_file)</span><br><span class="line">                            output.outputFile = new File(output_dir, fileName)</span><br><span class="line">                            println &quot;输出文件位置：&quot; + output.outputFile</span><br><span class="line">                        &#125; else &#123;</span><br><span class="line">                            output.outputFile = new File(outputFile.parent, fileName)</span><br><span class="line">                            println &quot;输出文件位置：&quot; + output.outputFile</span><br><span class="line">                        &#125;</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">      &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>####5. 多工程全局配置<br>1). 在project的根目录下的build.gradle定义ext全局变量<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">ext &#123; </span><br><span class="line">  compileSdkVersion = 22 </span><br><span class="line">  buildToolsVersion = &quot;23.0.1&quot; </span><br><span class="line">  minSdkVersion = 10 </span><br><span class="line">  targetSdkVersion = 22 </span><br><span class="line">  versionCode = 34 </span><br><span class="line">  versionName = &quot;v2.6.1&quot;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>2). 在各module的build.gradle中引用<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">android &#123; </span><br><span class="line">  compileSdkVersion rootProject.ext.compileSdkVersion </span><br><span class="line">  buildToolsVersion rootProject.ext.buildToolsVersion </span><br><span class="line"></span><br><span class="line">  defaultConfig &#123; </span><br><span class="line">    applicationId &quot;com.xxx.xxx&quot; </span><br><span class="line">    minSdkVersion rootProject.ext.minSdkVersion </span><br><span class="line">    targetSdkVersion rootProject.ext.targetSdkVersion </span><br><span class="line">    versionCode rootProject.ext.versionCode </span><br><span class="line">    versionName rootProject.ext.versionName </span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>####6. 混淆代码<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">//混淆编译</span><br><span class="line">minifyEnabled true</span><br><span class="line">proguardFiles getDefaultProguardFile(&apos;proguard-android.txt&apos;), &apos;proguard-rules.pro&apos;</span><br></pre></td></tr></table></figure></p>
<p>####7. 当前的编译时间、编译的机器、最新的commit版本添加到apk<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">android &#123; </span><br><span class="line">  defaultConfig &#123; </span><br><span class="line">      resValue &quot;string&quot;, &quot;build_time&quot;, buildTime() </span><br><span class="line">      resValue &quot;string&quot;, &quot;build_host&quot;, hostName() </span><br><span class="line">      resValue &quot;string&quot;, &quot;build_revision&quot;, revision() </span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">def buildTime() &#123; </span><br><span class="line">      return new Date().format(&quot;yyyy-MM-dd HH:mm:ss&quot;)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">def hostName() &#123; </span><br><span class="line">      return System.getProperty(&quot;user.name&quot;) + &quot;@&quot; + InetAddress.localHost.hostName</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">def revision() &#123; </span><br><span class="line">      def code = new ByteArrayOutputStream() </span><br><span class="line">      exec &#123; </span><br><span class="line">        commandLine &apos;git&apos;, &apos;rev-parse&apos;, &apos;--short&apos;, &apos;HEAD&apos; </span><br><span class="line">        standardOutput = code </span><br><span class="line">      &#125; </span><br><span class="line">      return code.toString()</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>####8. buildConfigField自定义配置<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">buildTypes &#123; </span><br><span class="line">  debug &#123; </span><br><span class="line">    buildConfigField &quot;boolean&quot;, &quot;LOG_DEBUG&quot;, &quot;true&quot;//是否输出LOG信息   </span><br><span class="line">    buildConfigField &quot;String&quot;, &quot;API_HOST&quot;, &quot;\&quot;http://api.test.com\&quot;&quot;//API Host </span><br><span class="line">  &#125; </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>####9. dex突破65535的限制<br>1). 在defaultConfig节点使能多DEX功能<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">```</span><br><span class="line">2). 引入multidex库文件</span><br></pre></td></tr></table></figure></p>
<p>dependencies {<br>  compile ‘com.android.support:multidex:1.0.0’<br>}<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">3). 继承MultiDexApplication</span><br><span class="line"></span><br><span class="line">####10. Task任务</span><br><span class="line">1). 获取全部任务</span><br></pre></td></tr></table></figure></p>
<p>gradlew tasks -q<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">其中-q表示忽略gradle本身的log信息，加上这个参数可以屏蔽很多无关的输出，不加也不会影响执行。执行后显示如下：</span><br></pre></td></tr></table></figure></p>
<p>F:\test\GradleTest&gt;gradlew tasks -q</p>
<hr>
<h2 id="All-tasks-runnable-from-root-project"><a href="#All-tasks-runnable-from-root-project" class="headerlink" title="All tasks runnable from root project"></a>All tasks runnable from root project</h2><h2 id="Android-tasks"><a href="#Android-tasks" class="headerlink" title="Android tasks"></a>Android tasks</h2><p>androidDependencies - Displays the Android dependencies of the project.<br>signingReport - Displays the signing info for each variant.<br>sourceSets - Prints out all the source sets defined in this project.</p>
<h2 id="Build-tasks"><a href="#Build-tasks" class="headerlink" title="Build tasks"></a>Build tasks</h2><p>assemble - Assembles all variants of all applications and secondary packages.<br>assembleAndroidTest - Assembles all the Test applications.<br>assembleDebug - Assembles all Debug builds.<br>assembleRelease - Assembles all Release builds.<br>build - Assembles and tests this project.<br>buildDependents - Assembles and tests this project and all projects that depend on it.<br>buildNeeded - Assembles and tests this project and all projects it depends on.<br>clean - Deletes the build directory.<br>compileDebugAndroidTestSources<br>compileDebugSources<br>compileDebugUnitTestSources<br>compileReleaseSources<br>compileReleaseUnitTestSources<br>mockableAndroidJar - Creates a version of android.jar that’s suitable for unit tests.</p>
<h2 id="Build-Setup-tasks"><a href="#Build-Setup-tasks" class="headerlink" title="Build Setup tasks"></a>Build Setup tasks</h2><p>init - Initializes a new Gradle build. [incubating]<br>wrapper - Generates Gradle wrapper files. [incubating]</p>
<h2 id="Help-tasks"><a href="#Help-tasks" class="headerlink" title="Help tasks"></a>Help tasks</h2><p>buildEnvironment - Displays all buildscript dependencies declared in root project ‘GradleTest’.<br>components - Displays the components produced by root project ‘GradleTest’. [incubating]<br>dependencies - Displays all dependencies declared in root project ‘GradleTest’.<br>dependencyInsight - Displays the insight into a specific dependency in root project ‘GradleTest’.<br>help - Displays a help message.<br>model - Displays the configuration model of root project ‘GradleTest’. [incubating]<br>projects - Displays the sub-projects of root project ‘GradleTest’.<br>properties - Displays the properties of root project ‘GradleTest’.<br>tasks - Displays the tasks runnable from root project ‘GradleTest’ (some of the displayed tasks may belong to subprojects).</p>
<h2 id="Install-tasks"><a href="#Install-tasks" class="headerlink" title="Install tasks"></a>Install tasks</h2><p>installDebug - Installs the Debug build.<br>installDebugAndroidTest - Installs the android (on device) tests for the Debug build.<br>uninstallAll - Uninstall all applications.<br>uninstallDebug - Uninstalls the Debug build.<br>uninstallDebugAndroidTest - Uninstalls the android (on device) tests for the Debug build.<br>uninstallRelease - Uninstalls the Release build.</p>
<h2 id="Verification-tasks"><a href="#Verification-tasks" class="headerlink" title="Verification tasks"></a>Verification tasks</h2><p>check - Runs all checks.<br>connectedAndroidTest - Installs and runs instrumentation tests for all flavors on connected devices.<br>connectedCheck - Runs all device checks on currently connected devices.<br>connectedDebugAndroidTest - Installs and runs the tests for debug on connected devices.<br>deviceAndroidTest - Installs and runs instrumentation tests using all Device Providers.<br>deviceCheck - Runs all device checks using Device Providers and Test Servers.<br>lint - Runs lint on all variants.<br>lintDebug - Runs lint on the Debug build.<br>lintRelease - Runs lint on the Release build.<br>test - Run unit tests for all variants.<br>testDebugUnitTest - Run unit tests for the debug build.<br>testReleaseUnitTest - Run unit tests for the release build.</p>
<h2 id="Other-tasks"><a href="#Other-tasks" class="headerlink" title="Other tasks"></a>Other tasks</h2><p>clean<br>extractProguardFiles<br>jarDebugClasses<br>jarReleaseClasses<br>transformResourcesWithMergeJavaResForDebugUnitTest<br>transformResourcesWithMergeJavaResForReleaseUnitTest</p>
<p>To see all tasks and more detail, run gradlew tasks –all<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">2). 创建任务</span><br></pre></td></tr></table></figure></p>
<p>// 定义任务<br>task hello<br>// 附带的动作–最后一个<br>hello.doLast {<br>    println(“hello doLast”)<br>}<br>// 附带的动作–第一个<br>hello.doFirst {<br>    println(“hello doFirst”)<br>}<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">添加的位置在Other tasks任务中会出现</span><br><span class="line">![task.png](https://upload-images.jianshu.io/upload_images/3110861-094b723434b52b89.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)</span><br><span class="line"></span><br><span class="line">3). 执行任务</span><br></pre></td></tr></table></figure></p>
<p>gradlew hello -q<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">结果：</span><br><span class="line">![hello task.png](https://upload-images.jianshu.io/upload_images/3110861-c36960979c639ecf.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)</span><br><span class="line"></span><br><span class="line">4). 依赖</span><br></pre></td></tr></table></figure></p>
<p>// 定义任务<br>task hello<br>// 附带的动作–最后一个<br>hello.doLast {<br>    println(“hello doLast”)<br>}<br>// 附带的动作–第一个<br>hello.doFirst {<br>    println(“hello doFirst”)<br>}<br>// 依赖<br>task world(dependsOn: “hello”) &lt;&lt; {<br>    println(“world”)<br>}<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">执行结果:</span><br><span class="line">![world task.png](https://upload-images.jianshu.io/upload_images/3110861-215b694acd75e950.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)</span><br><span class="line"></span><br><span class="line">其中：</span><br></pre></td></tr></table></figure></p>
<p>task xxx &lt;&lt; {<br>}<br>这样的语法等价于<br>task xxx<br>xxx.dolast {<br>}<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">####11. 查看包依赖关系</span><br></pre></td></tr></table></figure></p>
<p>gradlew.bat :app:dependencies –configuration compile<br><code>`</code></p>
<p>####</p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blog/2018/08/06/Android-Special-Function/Android-Fragment懒加载/" rel="next" title="Android-Fragment懒加载">
                <i class="fa fa-chevron-left"></i> Android-Fragment懒加载
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/2018/08/06/Android-Special-Function/Android-Jcenter-依赖完整版/" rel="prev" title="Android-Jcenter-依赖完整版">
                Android-Jcenter-依赖完整版 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            Overview
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/blog/images/avatar.jpeg"
                alt="凌浩雨" />
            
              <p class="site-author-name" itemprop="name">凌浩雨</p>
              <p class="site-description motion-element" itemprop="description">专业从事于移动端开发，Android与iOS均有涉及，主做Android开发与React Native开发</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/blog/archives/">
              
                  <span class="site-state-item-count">393</span>
                  <span class="site-state-item-name">posts</span>
                </a>
              </div>
            

            

            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#All-tasks-runnable-from-root-project"><span class="nav-number">1.</span> <span class="nav-text">All tasks runnable from root project</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Android-tasks"><span class="nav-number">2.</span> <span class="nav-text">Android tasks</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Build-tasks"><span class="nav-number">3.</span> <span class="nav-text">Build tasks</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Build-Setup-tasks"><span class="nav-number">4.</span> <span class="nav-text">Build Setup tasks</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Help-tasks"><span class="nav-number">5.</span> <span class="nav-text">Help tasks</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Install-tasks"><span class="nav-number">6.</span> <span class="nav-text">Install tasks</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Verification-tasks"><span class="nav-number">7.</span> <span class="nav-text">Verification tasks</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Other-tasks"><span class="nav-number">8.</span> <span class="nav-text">Other tasks</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">凌浩雨</span>

  
</div>


  <div class="powered-by">Powered by <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a></div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">Theme &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/blog/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
